package com.ygy.utils;
/**
 * @className: ThreadLocalUtil
 * @author: Ye
 * @描述: 用ThreadLocal存取数据(token)
 * @date: 2024/3/11 13:41
 * @version: 1.0
 */
public class ThreadLocalUtil {
    //提供ThreadLocal对象，
    private final static ThreadLocal THREAD_LOCAL = new ThreadLocal();

    // 根据键获取值
    public static <T> T get(){//泛型方法
        return (T) THREAD_LOCAL.get();
    }

    //存键值对
    public static void set(Object value){
        THREAD_LOCAL.set(value);

    }
    //清除ThreadLocal 防止内存泄露
    public static void remove(){
        THREAD_LOCAL.remove();
    }
}
